package com.qf.web.servlet;

import com.qf.pojo.Emp;
import com.qf.pojo.PageBean;
import com.qf.service.EmpService;
import com.qf.service.impl.EmpServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *
 * 查询所有的员工，展示到浏览器
 *
 * servlet中
 *  获取请求数据
 *  调用service，处理业务
 *  响应浏览器
 *
 *
 * @author 千锋教育
 * @Company http://www.mobiletrain.org/
 * @Version 1.0
 */
@WebServlet("/selectAllEmp")
public class SelectAllEmpServlet extends HttpServlet {



    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //接收前端参数
        //获取当前页
        String pageNumStr = req.getParameter("pageNum");
        int pageNum = 1;
        if(pageNumStr != null) {
            pageNum = Integer.parseInt(pageNumStr);
        }
        //获取  每页条数
        String pageSizeStr = req.getParameter("pageSize");
        int pageSize = 3;
        if(pageSizeStr != null) {
            pageSize = Integer.parseInt(pageSizeStr);
        }


        EmpService empService = new EmpServiceImpl();
        //分页查询
        PageBean<Emp> pageBean = empService.findByPage(pageNum, pageSize);

        //把 员工列表数据存储 请求域
        req.setAttribute("pageBean", pageBean);
        //请求转发到 员工列表页面
        req.getRequestDispatcher("/page/empList.jsp").forward(req, resp);

    }

//    @Override
//    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//
//        EmpService empService = new EmpServiceImpl();
//        List<Emp> emps = empService.selectAll();
//
//        //把 员工列表数据存储 请求域
//        req.setAttribute("emps", emps);
//        //请求转发到 员工列表页面
//        req.getRequestDispatcher("/page/empList.jsp").forward(req, resp);
//
//    }
}
